home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18443 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Default values
  5. Date: Sat, 20 Apr 1996 15:27:59 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4lavog$5m6@news.halcyon.com>
  8. References: <26418@829921816>
  9. NNTP-Posting-Host: blv-pm2-ip16.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. "dan j" <djacobso@cs.indiana.edu> wrote:
  13.  
  14. >Is it somehow possible to use a class member variable as a default
  15. >value to a member function?  When, if ever, can variables serve as
  16. >default values?  For instance,
  17.  
  18. >class tree {
  19. >  tree_node * root;
  20.  
  21. >public:
  22. >  ...
  23. >  foo(tree_node * ptr = root) { (recursive); }
  24. >  ...
  25. >};    
  26.  
  27. >g++ (SunOS) says 'root' is not defined in this scope. 
  28.  
  29. >A special function foo2() called with 'root' serves the purpose:
  30.  
  31. >  foo(tree_node * ptr) { (recursive); }
  32. >  foo2(void) { foo(root); }
  33.  
  34. >But what is a better way to handle this?
  35.  
  36.  
  37. >dan j
  38.  
  39. Would your implementation suffer if the default value was NULL and the
  40. implementation chooses root if ptr == NULL?  
  41.  
  42.                     --Norm 
  43.  
  44.